from pydantic import BaseModel, Field, UUID4
from typing import Optional, List
from enum import Enum
from datetime import datetime

class RiskLevel(str, Enum):
    """风险等级枚举"""
    HIGH = 'high'
    MEDIUM = 'medium'
    LOW = 'low'

class RemediationStatus(str, Enum):
    """整改状态枚举"""
    IN_PROGRESS = 'in_progress'  # 整改中
    COMPLETED = 'completed'      # 已完成

class RemediationBase(BaseModel):   
    """Base schema for remediation operations."""
    item_id: Optional[UUID4] = Field(None, description="关联的检查项ID")
    plan_id: UUID4 = Field(..., description="关联的评估计划ID")
    title: str = Field(..., max_length=255, description="风险名称")
    description: str = Field(..., description="风险描述")
    suggestion: str = Field(..., description="整改建议")
    risk_level: RiskLevel = Field(..., description="风险等级（高风险/中风险/低风险）")
    status: RemediationStatus = Field(default=RemediationStatus.IN_PROGRESS, description="整改状态（整改中/已完成）")
    completion_date: Optional[datetime] = Field(None, description="完成整改时间（状态为已完成时自动记录）")

class RemediationCreate(RemediationBase):
    """Schema for creating a new remediation item."""
    pass

class RemediationUpdate(BaseModel):
    """Schema for updating an existing remediation item."""
    title: Optional[str] = None
    description: Optional[str] = None
    suggestion: Optional[str] = None
    risk_level: Optional[RiskLevel] = None
    status: Optional[RemediationStatus] = None
    completion_date: Optional[datetime] = None

class RemediationInDBBase(RemediationBase):
    """Base schema for remediation item in database."""
    id: UUID4
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

class Remediation(RemediationInDBBase):
    """Schema for returning a remediation item."""
    pass

class RemediationList(BaseModel):
    """Schema for returning a list of remediation items."""
    items: List[Remediation] = Field(..., description="整改项列表")

class RemediationDeleteRequest(BaseModel):
    """Schema for deleting multiple remediation items."""
    ids: List[UUID4] = Field(..., description="要删除的整改项ID列表")

class RemediationStatusUpdate(BaseModel):
    """Schema for updating remediation status."""
    status: RemediationStatus = Field(..., description="整改状态")
